//
//  Status.swift
//  sinaWeibo
//
//  Created by LSY on 15/12/22.
//  Copyright © 2015年 lsy. All rights reserved.
//

import UIKit

class Status: NSObject {
    
  var created_at :String?

  var id : Int64 = 0
    
  var text : String?
    
  var source : String?
    
  var user:User?
//  配图图片
    var pic_urls:[[String:String]]?{
    
        didSet{
//        判断是否有值
        guard let array = pic_urls else{
            
            return
            }
//           遍历数组
            imageURLs = [NSURL]()
            
            for item in array{
                var urlString = item["thumbnail_pic"]!
                urlString = urlString.stringByReplacingOccurrencesOfString("ScaleAspectFill", withString: "larger")
            let url = NSURL(string: urlString)!
//                添加url
                imageURLs!.append(url)
            }
        }
    }
//    将配图数组转换成真正的URL
    var imageURLs: [NSURL]?
//    转发微博
    var retweeted_status:Status?
    
//    初始化方法
    init(dict:[String :AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
//    在次方法中进行user属性 的字典转模型
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            if let dict = value as? [String : AnyObject]{
//                字典转模型
            user = User(dict: dict)
//            print(user)
            }
            return
        }
        
//    在ci方法中retweeted_status进行属性 的字典转模型

        if key == "retweeted_status"{
            
            if let dict = value as? [String:AnyObject]{
            retweeted_status = Status(dict: dict)
    
            }
            return
        }
        
        
        super.setValue(value, forKey: key)
    }

//    过滤参数
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
//    重写description
    override var description:String{

    let key = ["created_at","id","text","source","user"]
    
        return dictionaryWithValuesForKeys(key).description
    }
    }
